@layout("/common/_container.html"){
<div class="ibox float-e-margins">
<style>
	input{
	 width:100%;
	 height:100%;
	}
	select{
	width:100%;
	height:100%;
	}
	</style>
    <div>
        <div class="form-horizontal" style='overflow:scroll;'>
        <!--  记录是否通过下拉框选择的值，如果值不为空，则不进行反写数据库的操作，如果值为空，则进行反写数据库的操作 -->
			<input type="hidden" id="carId" name="carId" value="yes">
			<input type="hidden" id="routeId" name="routeId" value="yes">
			<div class="row">
			<form id="carryBasicInformation">
			<input type="hidden" id="id" name="id" value="${item.carryBasicInformation.id}">
				<table border="1" cellpadding="4px" width="1000px">
					<tr>
						<td>基本信息：</td>
						<td colspan="7"></td>
					</tr>
					<tr>
						<td>装车编号:</td>
						<td><input id="carryId" name="carryId" type="text" value="${item.carryBasicInformation.carryId}" readonly="readonly" style="background-color:#eee"/></td>
						<td>装车日期:</td>
						<td><input id="carryDate" name="carryDate" type="text" value="${tool.dateType(item.carryBasicInformation.carryDate)}"onclick="laydate({istime: false, format: 'YYYY-MM-DD'})"/></td>
						<td>制单员:</td>
						<td><input id="carryTradePerson" name="carryTradePerson"  value="${item.carryBasicInformation.carryTradePerson}"readonly="readonly" type="text" style="background-color:#eee"/></td>
						<td>审核员:</td>
						<td><input id="carryCheck" name="carryCheck" readonly="readonly" type="text" style="background-color:#eee"/></td>
					</tr>
					<tr>
						<td>车号:</td>
						<td><input id="carryCarId" name="carryCarId" value="${item.carryBasicInformation.carryCarId}"type="text"/></td>
						 <!-- 车辆信息的下拉选择框 -->
           				 <div id="showCar" class="menuContent"
			                 style="display: none; position: absolute; z-index: 200;">
			                <ul id="show-Car" class="ztree tree-box" style="width: 230px !important;">
			                </ul>
			            </div>
						<td>驾驶员：</td>
						<td><input id="carryCarDriver" name="carryCarDriver" value="${item.carryBasicInformation.carryCarDriver}" style="background-color:#eee" readOnly="readOnly" type="text"/></td>
						<td>联系电话：</td>
						<td><input id="carryCarDriverTell" name="carryCarDriverTell" value="${item.carryBasicInformation.carryCarDriverTell}" readOnly="readOnly" style="background-color:#eee" type="text"/></td>
						<td>手机：</td>
						<td><input id="carryCarDriverMobile" name="carryCarDriverMobile" value="${item.carryBasicInformation.carryCarDriverMobile}" readOnly="readOnly" style="background-color:#eee" type="text"/></td>
					</tr>
					<tr>
						<td>车次:</td>
						<td><input id="carryNumber" name="carryNumber"  value="${item.carryBasicInformation.carryNumber}" type="text" readonly="readonly" style="background-color:#eee"/></td>
						<td>物流线路:</td>
						<td><input id="carryRouteId" name="carryRouteId" value="${item.carryBasicInformation.carryRouteId}" type="text"/></td>
						<!-- 物流线路的下拉选择框 -->
           				 <div id="showRoute" class="menuContent"
			                 style="display: none; position: absolute; z-index: 200;">
			                <ul id="show-Route" class="ztree tree-box" style="width: 230px !important;">
			                </ul>
						<td>始发站：</td>
						<td><input id="carryRouteStart" name="carryRouteStart" value="${item.carryBasicInformation.carryRouteStart}" readOnly="readOnly" style="background-color:#eee" type="text"/></td>
						<td>到站：</td>
						<td><input id="carryRouteEnd" name="carryRouteEnd" value="${item.carryBasicInformation.carryRouteEnd}" readOnly="readOnly" style="background-color:#eee" type="text"/></td>
					</tr>
					<tr>
						<td>备注：</td>
						<td colspan="7"><input id="carryRemark" name="carryRemark" value="${item.carryBasicInformation.carryRemark}" type="text"/></td>
					</tr>
				</table>
			</form>
			</div>
	<div class="row">
	<div class="col-sm-3">
              <#NameCon id="searchContract" name="搜索或选择合同号"/>
     </div>
	</div>
	<!-- 商品名的下拉选择框 -->
           				 <div id="showContract" class="menuContent"
			                 style="display: none; position: absolute; z-index: 200;">
			                <ul id="show-Contract" class="ztree tree-box" style="width: 300px !important;">
			                </ul>
			            </div>
			<div style='width:2550px;'>
			<form id="carryContractInformations">
				<table border="1" cellpadding="4px" width="2500px" class="table1">
					<tr>
						<td colspan="24">装车信息：</td>
					</tr>
					<tr>
						<td width="35px">序号</td>
						<td width="120px">合同号</td>
						<td width="70px">发货人</td>
						<td width="100px">发货人电话</td>
						<td width="250px">发货人地址</td>
						<td width="70px">收货人</td>
						<td width="100px">收货人电话</td>
						<td width="250px">收货人地址</td>
						<td width="145px">货物编号</td>
						<td width="250px">货物名称</td>
						<td width="250px">货物规格</td>
						
						<td width="100px">包装方式</td>
						<td width="115px">本次发货数量</td>
						<td width="100px">未发货数量</td>
						<td width="100px">库存总数量</td>
						<td width="90px">数量(件)</td>
						<td width="90px">重量(KG)</td>
						<td width="90px">体积(m³)</td>
						<td width="70px">运费</td>
						<td width="70px">信息费</td>
						<td width="70px">提货费</td>
						<td width="120px">仓库</td>
						<td width="130px">备注</td>
						<td width="80px">操作</td>
					</tr>
					
					 @for(carryContractInformation   in   item.carryContractInformations){ 
					<tr id="a">
						<td class="id">${carryContractInformationLP.index}</td>
						<td><input id='carryContractNumber' name='carryContractNumber' type='text' value="${carryContractInformation.carryContractNumber}" style="background-color:#eee" readonly='readonly'/></td>
						<td><input id='carryConsignerName' name='carryConsignerName' value="${carryContractInformation.carryConsignerName}" style="background-color:#eee" readonly='readonly' type='text'/></td>
						<td><input id='carryConsignerTell' name='carryConsignerTell' value="${carryContractInformation.carryConsignerTell}" style="background-color:#eee" readonly='readonly' type='text'/></td>
						<td><input id='carryConsignerPlace' name='carryConsignerPlace' value="${carryContractInformation.carryConsignerPlace}" style="background-color:#eee" readonly='readonly' type='text'/></td>
						<td><input id='carryConsigneeName' name='carryConsigneeName' value="${carryContractInformation.carryConsigneeName}" style="background-color:#eee" readonly='readonly' type='text'/></td>
						<td><input id='carryConsigneeTell' name='carryConsigneeTell' value="${carryContractInformation.carryConsigneeTell}" style="background-color:#eee" readonly='readonly' type='text'/></td>
						<td><input id='carryConsigneePlace' name='carryConsigneePlace' value="${carryContractInformation.carryConsigneePlace}" style="background-color:#eee" readonly='readonly' type='text'/></td>
						<td><input id='carryGoodsId' name='carryGoodsId' value="${carryContractInformation.carryGoodsId}" style="background-color:#eee" readonly='readonly' type='text'/></td>
						<td><input id='carryGoodsName' name='carryGoodsName' value="${carryContractInformation.carryGoodsName}"  style="background-color:#eee" readonly='readonly' type='text'/></td>
						<td><input id='carryGoodsModel' name='carryGoodsModel' value="${carryContractInformation.carryGoodsModel}" style="background-color:#eee" readonly='readonly' type='text'/></td>
						<td><input id='carryGoodsPackage' name='carryGoodsPackage' value="${carryContractInformation.carryGoodsPackage}" style="background-color:#eee" readonly='readonly' type='text'/></td>
						<td><input id='carryThisQuantity' name='carryThisQuantity' value="${carryContractInformation.carryThisQuantity}"/></td>
						<td><input id='carryUnQuantity' name='carryUnQuantity' value="${carryContractInformation.carryUnQuantity}" style="background-color:#eee" readonly='readonly' type='text'/></td>
						<td><input id='carryStockQuantity' name='carryStockQuantity'  value="${carryContractInformation.carryStockQuantity}" style="background-color:#eee" readonly='readonly' type='text'/></td>
						<td><input id='carryGoodsQuantity' name='carryGoodsQuantity' value="${carryContractInformation.carryGoodsQuantity}" style="background-color:#eee" readonly='readonly' type='text'/></td>
						<td><input id='carryGoodsWeight' name='carryGoodsWeight' value="${carryContractInformation.carryGoodsWeight}" style="background-color:#eee" readonly='readonly' type='text'/></td>
						<td><input id='carryGoodsVolume' name='carryGoodsVolume' value="${carryContractInformation.carryGoodsVolume}" style="background-color:#eee" readonly='readonly' type='text'/></td>
						<td><input id='carryGoodsFreight' name='carryGoodsFreight' value="${carryContractInformation.carryGoodsFreight}" style="background-color:#eee" readonly='readonly' type='text'/></td>
						<td><input id='carryGoodsMessagefee' name='carryGoodsMessagefee' value="${carryContractInformation.carryGoodsMessagefee}" style="background-color:#eee" readonly='readonly' type='text'/></td>
						<td><input id='carryGoodsPickupCharge' name='carryGoodsPickupCharge' value="${carryContractInformation.carryGoodsPickupCharge}" style="background-color:#eee" readonly='readonly' type='text'/></td>
						<td><input id='carryGoodsWarehouseName' name='carryGoodsWarehouseName' value="${carryContractInformation.carryGoodsWarehouseName}" style="background-color:#eee" readonly='readonly' type='text'/></td>
						<td><input id='carryGoodsRemark' name='carryGoodsRemark' value="${carryContractInformation.carryGoodsRemark}" style="background-color:#eee" readonly='readonly' type='text'/></td>
						<td><button type='button' onclick='del(this);' >删除</button></td>
						<input id="id" type="hidden" name="id" value="${carryContractInformation.id}"/>
						<input id="foreignKeyCarryId" type="hidden" name="foreignKeyCarryId" value="${carryContractInformation.foreignKeyCarryId}"/>
					</tr>
					@}
					<tr id="sumCopy">
						<td colspan="12">总计</td>
						<td id="carryCount"></td>
						<td id="unCarryCount"></td>
						<td id="stockCount"></td>
						<td id="sumCount"></td>
						<td id="sumWeight"></td>
						<td id="sumVolume"></td>
						<td id="sumFreight"></td>
						<td id="sumMessagefee"></td>
						<td id="sumPickupCharge"></td>
						<td colspan="3"></td>
					</tr>
				</table>
				</form>
			</div>
            <div class="row btn-group-m-t">
                <div class="col-sm-10">
                    <#button btnCss="info" name="提交" id="ensure" icon="fa-check" clickFun="CarryBasicInformationInfoDlg.editSubmit()"/>
                    <#button btnCss="danger" name="取消" id="cancel" icon="fa-eraser" clickFun="CarryBasicInformationInfoDlg.close()"/>
                </div>
            </div>
        </div>

    </div>
</div>
<script src="${ctxPath}/static/modular/system/carryBasicInformation/carryBasicInformation_info.js"></script>
<script>
//非负浮点数
var re = /^\d+(\.\d+)?$/ ;
//非负整数
var rf = /^\d+$/ ;

function testRe(re, s){ // 参数说明 re 为正则表达式 s 为要判断的字符 
	return re.test(s) 
} 


//本次发货数量的动态计算
$("body").on("keyup","[name='carryThisQuantity']",function(){ 
	//验证标志
	//判断是否通过验证，如果通过验证，则test保持不变，否则test为1
	var test1 = 0;
	//键盘弹起的时候计算未发货数量,并且更新未发货数量的总数
	var carryUnQuantity = $(this).parent().siblings().eq(12).children().eq(0);
	var carryStockQuantity =  $(this).parent().siblings().eq(13).children().eq(0);
	var a=Number($(this).val());
	if(testRe(rf,a)){
		var sum = Number(carryStockQuantity.val())-Number($(this).val());
		if(sum<0){
			alert("本次发货数量不得大于库存数量！");
			carryUnQuantity.val(carryStockQuantity.val());
			$(this).val("");
			test1 = 1;
		}else{
			carryUnQuantity.val(sum);
		}
	}else{
		alert("发货数量不能小于1,且必须为整数!");
		carryUnQuantity.val(carryStockQuantity.val());
		$(this).val("");
		test1 = 1;
	}
	
	//未发货数量的计算
	var f = 0;
	$("input[name='carryUnQuantity']").each(function(){
		var a ;
		a=Number($(this).val());
		if(testRe(rf,a)){
        	f += a;
		}
	});
	$("#unCarryCount").text(f);
	
	//本次发货数量计算
	var fee = 0;
	
	$("input[name='carryThisQuantity']").each(function(){
		var a ;
		if($(this).val()==""){
			a=0;
		}else{
			a=Number($(this).val());
		}
		if(testRe(rf,a)){
        	fee += a;
		}else{
			test1 = 1;
			alert("发货数量不能小于1,且必须为整数!");
			$(this).val("");
		}
	});
	
	if(test1==0){
		$("#carryCount").html(fee);
	}else{
		$("#carryCount").html("");
	}
});  

//初始化库存总数量，数量，重量，体积，运费，信息费，提货费信息
function initCount(){
	//初始化库存总数量
	var a = 0;
	$("input[name='carryStockQuantity']").each(function(){
		var count ;
		count=Number($(this).val());
		if(testRe(rf,a)){
        	a += count;
		}
	});
	$("#stockCount").text(a);
	
	//初始化数量
	var b = 0;
	$("input[name='carryGoodsQuantity']").each(function(){
		var count ;
		count=Number($(this).val());
		if(testRe(re,b)){
        	b+= count;
		}
	});
	$("#sumCount").text(b);
	
	//初始化重量
	var c = 0;
	$("input[name='carryGoodsWeight']").each(function(){
		var count ;
		count=Number($(this).val());
		if(testRe(re,c)){
        	c+= count;
		}
	});
	$("#sumWeight").text(c);
	
	//初始化体积
	var d = 0;
	$("input[name='carryGoodsVolume']").each(function(){
		var count ;
		count=Number($(this).val());
		if(testRe(re,d)){
        	d+= count;
		}
	});
	$("#sumVolume").text(d);
	
	//初始化运费
	var f = 0;
	$("input[name='carryGoodsFreight']").each(function(){
		var count ;
		count=Number($(this).val());
		if(testRe(re,d)){
        	f+= count;
		}
	});
	$("#sumFreight").text(f);
	
	//初始化信息费
	var g = 0;
	$("input[name='carryGoodsMessagefee']").each(function(){
		var count ;
		count=Number($(this).val());
		if(testRe(re,d)){
        	g+= count;
		}
	});
	$("#sumMessagefee").text(g);
	
	//初始化提货费
	var h = 0;
	$("input[name='carryGoodsPickupCharge']").each(function(){
		var count ;
		count=Number($(this).val());
		if(testRe(re,d)){
        	h+= count;
		}
	});
	$("#sumPickupCharge").text(h);
	
	//初始化本次发货数量
	var i = 0;
	$("input[name='carryThisQuantity']").each(function(){
		var count ;
		count=Number($(this).val());
		if(testRe(re,d)){
        	i+= count;
		}
	});
	$("#carryCount").text(i);
	
	
	//初始化未发货数量
	var j = 0;
	$("input[name='carryUnQuantity']").each(function(){
		var count ;
		count=Number($(this).val());
		if(testRe(re,d)){
        	j+= count;
		}
	});
	$("#unCarryCount").text(j);
}

//初始化序号
function initId(){
	var i = 1;
	$(".id").each(function(){
	    $(this).html(i++);
	});
}
//删除某一行
function del(obj){
	var a =  $(obj).parent().parent().children().eq(24).val();
	console.log("要删除的这行，id为"+a);
	if(a!= undefined){
		$.ajax({
			async : false,
			type : 'post',
			url : Feng.ctxPath+'/carryBasicInformation/deleteedit?id='+a,
			contentType : "application/json;charset=UTF-8",
			success : function(data) {
				if (data == 'SUCCESS') {
					$(obj).parent().parent().remove();
				} else {
					 alert("删除失败!该装车登记已经通过审核，请刷新页面重试！");
					  window.parent.CarryBasicInformation.table.refresh();
				        CarryBasicInformationInfoDlg.close();
				}
			},
			error : function(data) {
				 Feng.error("删除失败!");
			}
		});
	}else{
		$(obj).parent().parent().remove();
	}
	initId();	
	initCount();
}
$(function(){
	initCount();
});
</script>
@}
